import axios from 'axios'
//判断软件运行环境
const isDev = process.env.NODE_ENV === 'development'

const ajax = axios.create({
  baseURL: isDev ? 'http://localhost:3003' : '真实地址'
})
/**
 * 书籍上传
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 上传信息
 */
export const bookUpload = params => {
  console.log(params)
  return ajax.post('/api/bookupload', params)
}
/**
 * 书籍收藏
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 收藏列表信息
 */
export const bookCollect = params => {
  console.log(params)
  return ajax.post('/api/bookcollect', params)
}
/**
 * 取消收藏
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 取消信息
 */
export const bookCancelCollect = params => {
  console.log(params)
  return ajax.post('/api/bookcancelcollect', params)
}
/**
 * 书籍借阅
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 借阅信息
 */
export const bookBorrow = params => {
  console.log(params)
  return ajax.post('/api/bookborrow', params)
}
/**
 * 书籍归还
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 归还信息
 */
export const bookCancelBorrow = params => {
  console.log(params)
  return ajax.post('/api/bookcancelborrow', params)
}
/**
 * 书籍删除
 *
 * @param {String} userid 用户id
 * @param {String} bookid 书籍id
 * @return {Object} 删除信息
 */
export const bookDelete = params => {
  console.log(params)
  return ajax.post('/api/bookdelete', params)
}
/**
 * 获取书籍(id,关键字)
 *
 * @param {String} method 请求书籍方式
 * @return {Object} 书籍列表
 */
export const getBooksList = params => {
  console.log({ ...params })
  return ajax.post('/api/bookslist', { ...params })
}
/**
 * 获取管理书籍(管理员)
 *
 * @param {String} params 请求书籍状态
 * @return {Object} 书籍列表
 */
export const getAdminBooksList = params => {
  console.log(params)
  return ajax.post('/api/adminbookslist', params)
}
/**
 * 管理书籍状态
 *
 * @param {String} params 请求书籍状态
 * @return {Object} 书籍列表
 */
export const adminbooks = params => {
  console.log(params)
  return ajax.post('/api/adminbooks', params)
}
/**
 * 获取我的三类书籍(收藏,借阅,我的)
 *
 * @param {String} bookid 我的书籍id
 * @return {Object} 书籍列表
 */
export const getMyBooksList = bookid => {
  console.log(bookid)
  return ajax.post('/api/mybookslist', bookid)
}
// /**
//  * 按类型获取书籍
//  *
//  * @param {String} params 请求书籍类型
//  * @return {Object} 书籍列表
//  */
// export const getBooksListByClassify = params => {
//   console.log(params)
//   return ajax.post('/api/classifybookslist', params)
// }
